@extends('back.adminbase')
@section('content')
    <section class="hbox stretch">
        @include("back.public.left")
        <aside>
            <section class="vbox">
                <header class="header bg-white b-b clearfix">
                    <form class="talbe-search" method="get" action="{{url('back/ltlog/index')}}">
                        <div class="row m-t-sm">
                            <div class="col-sm-9 m-b-xs">
                            </div>
                            <div class="col-sm-3 m-b-xs">
                                <div class="input-group">
                                    <input class="input-sm form-control" name="keyword" value="{{ old('keyword') }}" placeholder="请输入读者ID或书名或ISBN码或分类号或条形码" type="text">
                                <span class="input-group-btn">
                                    <button class="btn btn-sm btn-default" type="submit" title="搜索">
                                        <i class="glyphicon glyphicon-search"></i> 搜索
                                    </button>
                                </span>
                                </div>
                            </div>
                        </div>
                    </form>
                </header>
                {{--select框--}}
                <div class="downlist">
                    <p>请选择柜子：</p>
                    <div class="clearfix">
                        <select name="local" id="local">
                          <?php
                            foreach ($shelves as $shelf){
                                echo " <option value ={$shelf->code}>{$shelf->name}第{$shelf->column}列</option>";
                            }
                            ?>
                        </select>
                    </div>
                    <p class="opt-btn">
                        <a href="javascript:void(0)" class="down-btn">确定</a>
                        <a href="javascript:void(0)" class="cancel-btn">取消</a>
                    </p>
                </div>
                <section class="scrollable  wrapper w-f">
                    <section class="panel panel-default">
                        <div class="table-responsive">
                            <table class="table table-hover m-b-none entity-view" data-path="/attendance/count/countDetail/id/{0}">
                                <thead>
                                <tr>
                                    <th style="text-align: center;width: 50px">序号</th>
                                    <th style="text-align: center;width: 50px">图片</th>
                                    <th style="text-align: center;width: 50px">ISBN</th>
                                    <th style="text-align: center;width: 100px">书名</th>
                                    <th style="text-align: center;width: 80px">分类号</th>
                                    <th style="text-align: center;width: 80px">条码号</th>
                                    <th style="text-align: center;width: 80px">读者ID</th>
                                    <th style="text-align: center;width: 130px">借书门ID</th>
                                    <th style="text-align: center;width: 130px">借书门日期</th>
                                    <th style="text-align: center;width: 130px">还书门ID</th>
                                    <th style="text-align: center;width: 130px">还书日期</th>
                                    <th style="text-align: center;width: 130px">书籍状态</th>
                                    <th style="text-align: center;width: 180px">操作</th>

                                </tr>
                                </thead>
                                <tbody>
                                <?php
                                $status_code = [
                                    '0' => '外借',
                                    '1' => '还书',
                                    '2' => '已售',
                                ];
                                ?>
                                @foreach ($res as $k=>$v)
                                    <tr>
                                        <td style="text-align: center;">{{$limit*($res->currentPage()-1)+$k+1}}</td>
                                        <td style="text-align: center;">
                                            <img src="{{config('config.picHostPrefix').$v->ImageUrl}}" width="80px" height="60px">
                                        </td>
                                        <td style="text-align: center;">{{$v->isbn}}</td>
                                        <td style="text-align: center;">{{$v->cTitle}}</td>
                                        <td style="text-align: center;">{{$v->ReqNo}}</td>
                                        <td style="text-align: center;">{{$v->Barcode}}</td>
                                        <td style="text-align: center;">{{$v->ReaderID}}</td>
                                        <td style="text-align: center;">{{$v->LendDoorID}}</td>
                                        <td style="text-align: center;">{{\App\Util\TimeHelper::formatDateTime($v->LendDate)}}</td>
                                        <td style="text-align: center;">{{$v->ReturnDoorID}}</td>
                                        <td style="text-align: center;">{{\App\Util\TimeHelper::formatDateTime($v->ReturnDate)}}</td>
                                        <td style="text-align: center;">{{$status_code[$v->BookState]}}</td>

                                        <?php if($v->BookState == 0){?>

                                        <td>
                                            <a data-back="{{ url('back/ltlog/gh/')}}" data-id="{{$v->SerialNo}}"  data-uid="{{$v->rUID}}"   class="gh label label-success">归还到上架</a>

                                            <a data-back="{{ url('back/ltlog/ghcol/'.$v->SerialNo)}}"  class="ghxj label label-danger">归还到待上架</a>
                                        </td>

                                        <?php
                                             }
                                        ?>

                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    </section>
                    <div>数量：{{$count}}</div>
                    <div style="text-align: center">{!! $res->appends($_GET)->render() !!}</div>
                </section>

            </section>
        </aside>
    </section>

@endsection

@section('addscript')
    <script>
        $(function(){
            $('.gh').click(function(){
                var url=$(this).attr("data-back");
                var id = $(this).attr("data-id");
                var uid = $(this).attr("data-uid");
                $('.downlist').show();

                $(".down-btn").click(function(){
                    var code=$('#local').val();
                    layer.confirm('您确定归还到漂流柜吗？', {
                        btn: ['确认','取消'] //按钮
                    }, function(){
                        $.ajax({
                            'url':url,
                            'type':'post',
                            'dataType':'json',
                            'data': {id:id,uid:uid,code:code },
                            'success':function(data){
                                if(data.success){
                                    layer.alert("归还成功！",function(){
                                        location.reload();
                                    });
                                }else{
                                    layer.alert(data.msg)
                                }
                            }
                        })
                    }, function(){

                    })
                })

            });
            //关闭弹窗
            $(".cancel-btn").click(function(){
                $(".downlist").hide();
            });


           $(".ghxj").click(function(){
            var url=$(this).attr("data-back");
            layer.confirm('您确定待上架吗？', {
                btn: ['确认','取消'] //按钮
            }, function(){
                $.ajax({
                    'url':url,
                    'type':"post",
                    'dataType':'json',
                    'success':function(data){
                        if(data.success){
                            layer.alert("待上架成功！",function(){
                                location.reload();
                            });
                        }else{
                            layer.alert(data.msg)
                        }
                    }
                })
            }, function(){

            })
          });
        });
    </script>
    <style>
        .clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden;}
        .clearfix{zoom:1;}
        .downlist{
            width: 300px;
            height: 300px;
            position: fixed;
            top: 50%;
            margin-top: -145px;
            left: 50%;
            margin-left: -200px;
            background: white;
            padding: 30px;
            z-index: 11;
            font-size: 16px;
        }

        .downlist div {
            font-size: 16px;
            margin: 25px 0px;
        }
        .downlist div span{
            float: left;
            position: relative;
            top: 7px;
            margin-right: 15px;
        }
         .downlist div a{
            text-align: center;
            display: inline-block;
            width: 30px;
            height: 28px;
            cursor: pointer;
            line-height: 28px;
            font-size: 20px;
            color: #999999;
            border: 1px solid #999999;
            background: #f6f6f6;
            margin: 0px;
            padding: 0px;
            float: left;
        }
        .downlist{
            display: none;
        }

         .downlist div select{
            height: 28px;
        }
        .downlist .opt-btn{
            text-align: center;
        }
        .downlist .opt-btn a{
            background: #f2f4f4;
            color: #333333;
            padding: 5px 20px;
            border-radius: 4px;
            margin-right: 10px;
        }

        .down-btn {
            text-align: center;
            margin-top: 25px;
        }
    </style>
@endsection
